/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Portions created by the Initial Developer are
 * Copyright (C) 2012 the Initial Developer.
 * All Rights Reserved.
 *
 * The Original Code is "http://semi-frame.googlecode.com/svn/trenk/".
 *
 * The Initial Developer of the Original Code is the author below.
 */
/**
 * @file NetConfig.h
 * @brief auto generated.
 * @author mornongcloud
 * @date 2011/07/21
 */

#ifndef SEMICONFNETCONFIG_H_
#define SEMICONFNETCONFIG_H_

#include "semi/conf/Configurator.h"
#include "semi/conf/TasksConfig.h"

namespace semi {
namespace conf {

/*
 * NetConfig
 *
 */
class NetConfig {
public:
	NetConfig();
	virtual ~NetConfig();

	bool load();
	bool setSharedMemory();

	/// @brief task config
	struct TcpConfig {
		char task_id[16]; // task ID
		short type; // 1:tcp

		short header_size;
		short length_start;
		short length_type; // 2:short 4:int 8:longlong

		short serv_port; // server port.
		short serv_size; // Max connection count.

		short dist_port; // Distant port.
		char dist_addr[32]; // Distant address.
	};

	struct TcpConfigs {
		TcpConfig tcpConfig[128];
		//		UdpConfig udpConfig[128];
	};

	semi::posix::SharedMemory mDb;

	static std::string config_file_name;
	static std::string share_file_name;

	TcpConfig getTcpConfig(std::string tskid);

	static std::string toString();

	util::ShortMap tasks; // Task to kick. 1:serv 2:client 3:both
	util::StringMap m_tcp_serv_port; // Server port.
	util::StringMap m_tcp_serv_size; // Max connection count.

	util::StringMap m_tcp_dist_port; // Distant port.
	util::StringMap m_tcp_dist_addr; // Distant address.

	short header_size;
	short length_start;
	short length_type;

	util::ShortMap m_header_size;
	util::ShortMap m_length_start;
	util::ShortMap m_length_type;

};

}
}

#endif /* SEMICONFNETCONFIG_H_ */
